/*
 * InvulgoTracker
 * Copyright (C) Thomas Andersen 2011 <thomas.1.andersen@gmail.com>
 *
 * InvulgoTracker is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * InvulgoTracker is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <gtk/gtk.h>
#include "i-day-load.h"
#include "task-time.h"
#include "taskid.h"

class BalanceView : public IDayLoad
{
public:
    BalanceView();
    virtual ~BalanceView();
    void Clean();
    void Restart();
    void Init(GtkWidget *view, gboolean sortable = FALSE);
    void CalcDay(guint year, guint month, guint day);
    void Data(gchar *name, gchar *timeStr, TaskId id);
    void AddToTask(TaskTime diff, gchar *taskName, TaskId id);
    bool GetFirst(gchar **name, gchar **timeStr);
    bool GetNext(gchar **name, gchar **timeStr);
protected:

private:
    static gint sort_iter_compare_func_date(GtkTreeModel *model, GtkTreeIter  *a, GtkTreeIter  *b, gpointer userdata);
    static gint sort_iter_compare_func_workhours(GtkTreeModel *model, GtkTreeIter  *a, GtkTreeIter  *b, gpointer userdata);
    static gint sort_iter_compare_func_actual(GtkTreeModel *model, GtkTreeIter  *a, GtkTreeIter  *b, gpointer userdata);
    gint sort_iter_compare_func (GtkTreeModel *model, GtkTreeIter  *a, GtkTreeIter  *b, gpointer userdata);
    static void column_date_clicked(GtkTreeViewColumn *treeviewcolumn, gpointer user_data);
    static void column_workhours_clicked(GtkTreeViewColumn *treeviewcolumn, gpointer user_data);
    static void column_actual_clicked(GtkTreeViewColumn *treeviewcolumn, gpointer user_data);
    void CalcMonth(guint year, guint month);
    void CalcPct(glong type);
    enum
    {
        COL_DATE = 0,
        COL_WORKHOURS,
        COL_ACTUAL,
        NUM_COLS
    };
    enum
    {
        SORT_DATE = 0,
        SORT_WORKHOURS,
        SORT_ACTUAL
    };

    GtkTreeModel *CreateModel();

    GtkTreeView *view;
    gboolean isSortable;
    GtkTreeModel *model;
    TaskTime taskTime;
    TaskTime totalTime;
    TaskTime *prevTime;
    gchar *prevName;
    TaskId prevId;
    GtkTreeIter currentIter;

    double totalWorkhours;
    double totalActual;

};

